package com.chinawayltd.ews.sample.manager.openApi.impl;

import com.chinawayltd.ews.openapi.Request;
import com.chinawayltd.ews.openapi.constant.Constants;
import com.chinawayltd.ews.openapi.constant.ContentType;
import com.chinawayltd.ews.openapi.constant.HttpHeader;
import com.chinawayltd.ews.openapi.enums.MethodEnum;
import com.chinawayltd.ews.openapi.util.MessageDigestUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: greeProject.timingTaskCenter
 * @description:
 * @author: xiazj
 * @create: 2018-05-21 16:23
 **/
public class BaseOpenApiManager {

    protected Request getPostRequest(String path, String body) throws Exception {
        Map<String, String> headers = new HashMap<String, String>();

        headers.put(HttpHeader.HTTP_HEADER_CONTENT_MD5, MessageDigestUtil.base64AndMD5(body));
        //（POST/PUT请求必选）请求Body内容格式
        headers.put(HttpHeader.HTTP_HEADER_CONTENT_TYPE, ContentType.CONTENT_TYPE_JSON);
        headers.put(HttpHeader.HTTP_HEADER_G7_TIMESTAMP, "" + System.currentTimeMillis());

        Request request = new Request(MethodEnum.POST, path, Constants.DEFAULT_TIMEOUT);
        request.setHeaders(headers);
        request.setJsonStrBody(body);

        return request;
    }

}
